//
// Created by sagnitude on 12/31/2015.
//

#include <iostream>
#include <crow/amalgamate/crow_all.h>
#include "Logic.h"

using namespace std;

int main() {

    crow::SimpleApp app;

    CROW_ROUTE(app, "/")([](){
        return "Hello world";
    });


    CROW_ROUTE(app, "/testConn.action") ([]{
        return "OK";
    });


    CROW_ROUTE(app, "/listAdsOfBeaconsMem.action") ([](const crow::request& req){

        char* endUserSn = req.url_params.get("endUserSn");
        char* triggerType = req.url_params.get("triggerType");
        char* appToken = req.url_params.get("appToken");
        char* jsonBeacons = req.url_params.get("jsonBeacons");

        if (jsonBeacons == nullptr) {
            return crow::response{400};
        }

        return crow::response{Logic::ListAd(endUserSn, triggerType, appToken, jsonBeacons)};
    });

    return 0;
}